package com.linQing.waterWork.config;

import com.linQing.waterWork.mapper.sql.SwsDatainfoMapper;
import com.linQing.waterWork.modle.vo.DataInfoListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class CacheInitializer implements ApplicationRunner {

    @Autowired
    private SwsDatainfoMapper swsDatainfoMapper;

    @Autowired
    private CacheManager cacheManager;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Map<Integer, String> numberToChineseMap = new HashMap<>();
        // 从数据库加载数据并放入缓存中
        numberToChineseMap.put(2010, "1#泵电流");
        numberToChineseMap.put(2011, "2#泵电流");
        numberToChineseMap.put(2017, "1#泵累计运行时间");
        numberToChineseMap.put(2018, "2#泵累计运行时间");
        numberToChineseMap.put(2000, "进水压力");
        numberToChineseMap.put(2001, "出水压力");
        numberToChineseMap.put(2002, "设定压力");
        numberToChineseMap.put(2012, "3#泵电流");
        numberToChineseMap.put(2006, "3#泵频率");
        numberToChineseMap.put(2239, "3#累计电量");
        numberToChineseMap.put(2035, "3#累计流量");
        numberToChineseMap.put(2034, "3#瞬时流量");
        numberToChineseMap.put(2422, "3#有功功率");
        numberToChineseMap.put(2434, "3#泵有功电能");
        numberToChineseMap.put(2405, "线电压");
        numberToChineseMap.put(2463, "3#定子温度1");
        numberToChineseMap.put(2464, "3#定子温度2");
        numberToChineseMap.put(2443, "3#电机转速");
        numberToChineseMap.put(2445, "3#泵效率");
        Cache cache = cacheManager.getCache("chineseNumberCache");
        if (cache != null) {
            cache.put("numberToChineseMap", numberToChineseMap);
        }
    }
}